import request from '@/utils/request'
import fileAPI from '@/utils/fileAPI'

export function list(data) {
  return request({
    url: '/system/user/list',
    method: 'post',
    data: data
  })
}
export function auditList(data) {
  return request({
    url: '/system/user/unapproved',
    method: 'post',
    data: data
  })
}
export function audit(data) {
  return request({
    url: '/system/user/userApproval',
    method: 'post',
    data: data
  })
}
export function listByPage(data) {
  return request({
    url: '/system/user/listByPage',
    method: 'post',
    data: data
  })
}
export function getAllUser(data) {
  return request({
    url: '/system/user/getAllUser',
    method: 'post',
    data: data
  })
}
export function changeStatus(data) {
  return request({
    url: '/system/user/changeStatus',
    method: 'post',
    data: data
  })
}
export function getInfo(data) {
  return request({
    url: '/system/user/' + data,
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: '/system/user/add',
    method: 'post',
    data: data
  })
}

export function changeAdmin(data) {
  return request({
    url: '/system/user/changeAdmin',
    method: 'post',
    data: data
  })
}
export function edit(data) {
  return request({
    url: '/system/user/edit',
    method: 'post',
    data: data
  })
}
export function remove(data) {
  return request({
    url: '/system/user/delete',
    method: 'post',
    data: data
  })
}
export function disabled(data) {
  return request({
    url: '/system/user/disabled',
    method: 'post',
    data: data
  })
}
export function unassigned(data) {
  return request({
    url: '/system/user/unassigned',
    method: 'post',
    data: data
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/system/user/' + userId,
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/system/user',
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/system/user',
    method: 'put',
    data: data
  })
}
export function updatePassword(data) {
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'post',
    data: data
  })
}

// 删除用户
export function delUser(userId) {
  return request({
    url: '/system/user/' + userId,
    method: 'delete'
  })
}
export function importMethod(files) {
  const formData = new FormData()
  for (let i = 0; i < files.length; i++) {
    formData.append('file', files[i], files[i].name)
  }
  return fileAPI({
    url: '/system/user/import',
    method: 'post',
    data: formData
  })
}
export function getSecondUserNumber(data) {
  return request({
    url: '/system/company/getSecondUserNumber',
    method: 'post',
    data: data
  })
}
